/*
 * protocol_code.h
 *
 *  Created on: Feb 13, 2010
 *      Author: Spartans-UMBC
 */

#include <stdio.h>
#include "usart.h"     // Shall be included before FreeRTOS header files, since'inline' is defined to ''; leading to
                       // link errors
#include "conf_usb.h"

#include "board.h"
#ifdef FREERTOS_USED
#include "FreeRTOS.h"
#include "task.h"
#endif
#include "usb_drv.h"
#include "gpio.h"
#include "joystick.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "device_cdc_task.h"
#include "uart_usb_lib.h"



#include "compiler.h"
#include "preprocessor.h"
#include "pm.h"
#include "gpio.h"
#include "board.h"
#include <stdlib.h>
#include <ctype.h>
//#include <delay.h>
//#include <sleep.h>
#include <string.h>
#include <limits.h>


// ASSIGN GPIO pins to the control signals




// ASSIGN GPIO pins to the control signals
//NEW MAPPING

#define SRQ   AVR32_PIN_PA22
#define EOI AVR32_PIN_PA16        //
#define DAV AVR32_PIN_PA15
#define NRFD AVR32_PIN_PA19        //
#define NDAC AVR32_PIN_PA18        //
#define IFC AVR32_PIN_PA17
#define ATN AVR32_PIN_PA14
#define REN  AVR32_PIN_PA21       //
#define TE  AVR32_PIN_PA26
#define DC  AVR32_PIN_PA25


//GPIB
#define DATA1 AVR32_PIN_PA13        // Service Request
#define DATA2 AVR32_PIN_PA12        // Attention
#define DATA3 AVR32_PIN_PA10        // End Or Identity
#define DATA4 AVR32_PIN_PA04        // Data Valid
#define DATA5 AVR32_PIN_PA03        // Not Ready For Data--------------CHECK
#define DATA6 AVR32_PIN_PA02        // Not Data Accepted
#define DATA7 AVR32_PIN_PA01         // Interface Clear
#define DATA8 AVR32_PIN_PA00





#define nACK  AVR32_PIN_PB16
#define BUSY AVR32_PIN_PB17        //
#define PAPEREND AVR32_PIN_PB18
#define SELECT AVR32_PIN_PB19        //
#define nAUTOLF AVR32_PIN_PB20        //
#define nERROR AVR32_PIN_PB21
#define nINIT AVR32_PIN_PB22
#define nSELECTIN  AVR32_PIN_PB27       //
#define nSTROBE AVR32_PIN_PA28       //  CHECK IF VALID!!!!!!!!!!!!!!



//DATA LINES
//TEMP SHARED BY PARALLEL-GPIB
// PARALLEL


#define DATA1_PA AVR32_PIN_PA29        // Service Request
#define DATA2_PA AVR32_PIN_PA30        // Attention
#define DATA3_PA AVR32_PIN_PB04        // End Or Identity
#define DATA4_PA AVR32_PIN_PB10        // Data Valid
#define DATA5_PA AVR32_PIN_PB11        // Not Ready For Data--------------CHECK
#define DATA6_PA AVR32_PIN_PB12        // Not Data Accepted
#define DATA7_PA AVR32_PIN_PB13         // Interface Clear
#define DATA8_PA AVR32_PIN_PB14



/*//PARALLEL DECLARATIONS -TEMP SHARED WITH GPIB
#define nACK  AVR32_PIN_PB16
#define BUSY AVR32_PIN_PB17        //
#define PAPEREND AVR32_PIN_PB18
#define SELECT AVR32_PIN_PB19        //
#define nAUTOLF AVR32_PIN_PB20        //
#define nERROR AVR32_PIN_PB21
#define nINIT AVR32_PIN_PB22
#define nSELECTIN  AVR32_PIN_PB27       //
#define nSTROBE AVR32_PIN_PA28       //  CHECK IF VALID!!!!!!!!!!!!!!


*/


#ifndef PROTOCOL_CODE_H_
#define PROTOCOL_CODE_H_



void sendUSBString(char input[]);

//USB to SERIAL
void usb2ser();

//USB to Parallel
void usb2par();

void resetBus();

char *chartobin ( unsigned char c );

char binaryToAscii(int buffer[]);

void enablePins();

int* createDataChar();

void SetDataLines(char controls[]);

void SetControlLines(char controls[]);

void setPinsDependingOnData(char c);

void setPinsDependingOnDataParallel (char c);

void SetListenerTalker(char c);

void RcvBinData();

void init_GPIB();

int getPcInt();

int sendGPIBData();

int readGPIB();
int readGPIBWF();
char binaryToAsciiPar(int buffer[]);
void enableParallelPins();
int* createDataCharParallel();

void setupParallelWrite();
void setupParallelRead();

#endif /* PROTOCOL_CODE_H_ */
